package com.example.demo.controller.admin;

import com.example.demo.Util.Result;
import com.example.demo.Util.ResultUtil;
import com.example.demo.mapper.GradeMap;
import com.example.demo.po.grade;
import com.example.demo.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/grade")
public class GradeController {


    @Autowired
    GradeMap gradeMap;

    @Autowired
    GradeService gradeService;

//
   @PostMapping("/save")
   public Result SaveGrade(@RequestBody  grade g){

     Result result = gradeService.SaveGrade(g);

       return result;
    }

    @GetMapping("/delete/{id}")
    public Result DeleteGrade(@PathVariable int id){

        gradeMap.DeleteGrade(id);
       return ResultUtil.success("删除成功");
    }

    @PostMapping("/update")
    public Result UpdateGrade(@RequestBody grade g){
       Result result = gradeService.UpdateGrade(g);
       return result;
    }

    @GetMapping("/get")
    public Result GetGradeList(){

       return ResultUtil.success(gradeMap.GetGradeList());
    }

    @GetMapping("/search")
    public Result GetGradeListByName(@RequestParam("name") String name){

       if(name==null||name.isEmpty()){
           return ResultUtil.success(gradeMap.GetGradeList());
       }

       return ResultUtil.success(gradeMap.GetGradeListByName("%"+name+"%"));
    }
}
